<template>
  <div class="indexbox clearfix">
    <div class="leftbox left">
        <Sidebar/>
    </div>
    <div class="rightbox left">
        <Title/>
        <div class="topbar flex between item-center">
            <div>
                <p class="small" style="margin-bottom: 3px;">首页 / 我的主页</p>
                <h4>我的主页</h4>
            </div>
            <ul class="flex item-center">
                <!-- <li>
                    <el-input size="mini" placeholder="请输入搜索内容"></el-input>
                </li> -->
                <li class="small" style="cursor: pointer">
                    <router-link tag="span" to="/">
                        <span class="iconfont" style="">&#xe729;</span>
                        <span>首页</span>
                    </router-link>
                </li>
                <li class="small">
                    <el-dropdown @command="handleCommand">
                        <span class="el-dropdown-link">
                            <span class="iconfont" style="">&#xe64b;</span>
                            设置<i class="el-icon-arrow-down el-icon--right"></i>
                        </span>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item command="logout">退出</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </li>
                <li class="small">
                    <span class="iconfont" style="">&#xebcb;</span>
                    <span>提醒</span>
                </li>
            </ul>
        </div>
        <div class="infomation shadow-bottom flex between item-center">
            <div class="clearfix">
                <div class="left imgbox">
                    <img width="100%" :src="user.imageUrl" alt="">
                </div>
                <div class="left namebox">
                    <h2>{{user.name}}</h2>
                    <p class="small">山东干部网络学习学院 / 计算机科学与技术</p>
                </div>
            </div>
            <div>
                <span style="color: #000">学年：</span>
                <el-select v-model="year" placeholder="请选择" size="mini">
                    <el-option label="2023" value="2023"></el-option>
                </el-select>
            </div>
        </div>
        <div class="tongji" v-if="showTongji">
            <ul class="flex between">
                <li class="flex between item-center shadow" v-for="item of tongjis" :key="item.id">
                    <div>
                        <h6 class="small">{{item.title}}</h6>
                        <div class="value">
                            <span class="black bold">{{item.value}}</span>
                            <span class="middle bold">{{ item.name }}</span>
                        </div>
                    </div>
                    <div class="iconfont">&#xe64b;</div>
                </li>
            </ul>
        </div>
        <router-view />
    </div>
    <!-- <footer>
        底部导航
    </footer> -->
  </div>
</template>

<script>

import Sidebar from '@/components/Sidebar'
import Title from '@/components/Title'
import { logout, getUser } from '@/utils/auth'
export default {

    components: {
        Sidebar,
        Title
    },
    data() {
        return {
            user: {},
            year: '2023',
            tongjis: [
                { id: 1, title: '完成课时', value: 50, name: '学时', icon: '&#xe64b;' },
                { id: 2, title: '完成课程数', value: 15, name: '门', icon: '&#xe64b;' },
                { id: 3, title: '完成考试数', value: 3, name: '次', icon: '&#xe64b;' },
                { id: 4, title: '证书数量', value: 7, name: '个', icon: '&#xe64b;' }
            ],
            showTongji: true
        }
    },
    created() {
        this.showTongji = '/info/index' == this.$route.path
    },

    mounted() {
        this.user = getUser()
        console.log(this.user)
        // console.log(this.$route)
        
    },
    watch: {
        '$route.path': function(val) {
            this.showTongji = '/info/index' == val
        }
    },
    methods: {
        handleCommand(command) {
            if ('logout' === command) {
                console.log(123)
                logout()
                this.$router.push('/')
            }
            
            
        }
    }

}
</script>

<style lang="scss" scoped>
$left-width: 230px;
.indexbox {
    // min-height: 100vh;
    width: 1400px;
    margin: auto;
    .leftbox {
        width: $left-width;
        height: 100%;
        padding: 15px;
    }
    .rightbox {
        position: relative;
        width: calc(100% - #{$left-width});
        // height: 100vh;
        overflow-y: auto;
        padding: 0 15px 15px 0;
        .topbar {
            position: absolute;
            top: 20px;
            left: 15px;
            // 父内边距 两个 15px，加自已left 15px
            width: calc(100% - 45px);
            div,
            ul>li{
                color: #fff;
            }
            ul {
                li {
                    margin: 0 5px;
                }
            }
            
        }
        .infomation {
            padding: 10px;
            height: 80px;
            width: calc(100% - 40px);
            margin: -55px auto 0;
            position: relative;
            background: #fff;
            border-radius: 10px;
            .imgbox {
                width: 60px;
                height: 60px;
                text-align: center;
                line-height: 60px;
                border-radius: 5px;
                overflow: hidden;
            }
            .namebox {
                height: 60px;
                margin-left: 15px;
                h2 {
                    font-size: 18px;
                    font-weight: 600;
                    color: #000;
                    padding: 5px 0;
                }
                p {
                    font-weight: 600;
                }
            }
        }
        .tongji {
            margin: 20px 0;
            ul {
                li {
                    width: 24%;
                    padding: 10px;
                    .value {
                        &>span:first-of-type {
                            font-size: 22px;
                            margin-right: 7px;
                        }
                        &>span:last-of-type {
                            color: green;
                        }
                    }
                    .iconfont {
                        padding: 10px;
                        border-radius: 10px;
                        font-size: 22px;
                        background: var(--color-primary);
                        color: #fff;
                    }
                }
            }
        }
    }
    footer {
        position: fixed;
        height: 50px;
        left: 0;
        right: 0;
        bottom: 0;
    }
}
.el-dropdown-link {
    cursor: pointer;
  }
</style>